package com.ipod.ipod2;


import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Main extends ListActivity {
	
	static final int REQUEST_PLAY_SONG = 1;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        String[] menuItems = getResources().getStringArray(R.array.main_menu_items_array);
        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, menuItems));
        
        AnimationSet set = new AnimationSet(true);
        
        //Fade in
//        Animation animation = new AlphaAnimation(0.0f, 1.0f);
//        animation.setDuration(100);
//        set.addAnimation(animation);
        
        //From top to bottom
//        animation = new TranslateAnimation(
//        		Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
//        		Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
//        );
        
        //Brings in each item in the listview from left to right
        Animation animation = new TranslateAnimation(
        		Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f,
        		Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f
        );
        
        animation.setDuration(500);
        set.addAnimation(animation);
        
        LayoutAnimationController controller = new LayoutAnimationController(set);//, 0.5f);          
        
        ListView lv = getListView();
        
        lv.setLayoutAnimation(controller);
        
        
        
        
        
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(new OnItemClickListener() {
        	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        		
        		//TODO if music then switch to music menu
        		//TODO pass playlist or album or song name(s) to nowplaying?
        		
                Intent i = new Intent(view.getContext(), NowPlaying.class);
                i.putExtra("SONG", "Song");
                //i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                //Start the activity
                startActivityForResult(i,REQUEST_PLAY_SONG);
        		
        		//Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        	}
        });
        
        
    }

}